/**
 * 缓存路由信息

 */
import { defineStore } from 'pinia'
import Cache from '@/global/Cache'
import * as CacheKey from '@/global/CacheKey'

export default defineStore('visitedRoutes', {
  state: () => {
    return {
      visitedRoutes: Cache.get(CacheKey.VISITED_ROUTES, [])
    };
  },
  actions: {
    loadState() {
      const currentState = Cache.get(CacheKey.VISITED_ROUTES, [])
      this.$patch({ visitedRoutes: JSON.parse(currentState) });
    },
    saveState(newState: any[]) {
      this.visitedRoutes = newState;
      Cache.save(CacheKey.VISITED_ROUTES, this.visitedRoutes);
      // this.$patch({ visitedRoutes: newState });
    },
    getState(): any[] {
      return Cache.get(CacheKey.VISITED_ROUTES, []);
    },
    resetState() {
      this.$reset();
    },
    clearState() {
      this.visitedRoutes = []
      Cache.remove(CacheKey.VISITED_ROUTES);
    }
  }
})